import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2025-09-23
 * Time: 18:26
 */

class Solution{
    public ArrayList<Integer> InterSection(ArrayList<Integer> nums1, ArrayList<Integer> nums2){
        boolean[] hash = new boolean[1010];

        for(int x : nums1){
            hash[x] = true;
        }

        ArrayList<Integer> ret = new ArrayList<>();
        for(int x : nums2){
            if(hash[x]){
                ret.add(x);
                hash[x] = false;
            }
        }
        return ret;
    }
}

public class demo2 {


    public static void main(String[] args) {
        ArrayList<Integer> nums1 = new ArrayList<>();
        ArrayList<Integer> nums2 = new ArrayList<>();
        Solution solution = new Solution();

        nums1.add(1);
        nums1.add(2);

        nums2.add(2);
        nums2.add(2);
        nums2.add(2);
        nums2.add(3);

        ArrayList<Integer> ret = new ArrayList<>();
        ret = solution.InterSection(nums1, nums2);
        System.out.println(ret);

    }
}
